//
//  WBComposeTextView.swift
//  simpleWeibo
//
//  Created by sunmumu on 2019/5/5.
//  Copyright © 2019 孙林. All rights reserved.
//

import UIKit

class WBComposeTextView: UITextView {

    fileprivate lazy var placeholderLabel = UILabel()

    override func awakeFromNib() {
        setupUI()
        setupNotification()
    }
    
    @objc fileprivate func textChange(n: Notification) {
        self.placeholderLabel.isHidden = self.hasText
    }
}

extension WBComposeTextView {
    
    func setupUI() {
        
        placeholderLabel.text = "分享新鲜事..."
        placeholderLabel.font = self.font
        placeholderLabel.textColor = UIColor.lightGray
        placeholderLabel.frame.origin = CGPoint(x: 5, y: 8)
        placeholderLabel.sizeToFit()
        
        addSubview(placeholderLabel)
    }
    
    func setupNotification() {
        NotificationCenter.default.addObserver(self, selector: #selector(textChange), name: UITextView.textDidChangeNotification, object: self)
        
    }
    
}
